import Vue from 'vue'
import Router from 'vue-router'

import Home from '@/pages/views/Home'
import TestView1 from '@/pages/views/TestView1'
import TestView2 from '@/pages/views/TestView2'
import TestView3 from '@/pages/views/TestView3'
import TestView4 from '@/pages/views/TestView4'
import Login from '@/pages/start/Login'
import Main from '@/pages/main/Main'
import Register from '@/pages/start/Register'

/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [{
    path: '/',
    redirect: '/login',
    meta: {
      title: '登录页面',
      logStatus: false
    }
  }, {
    path: '/login',
    name: 'login',
    component: Login,
    meta: {
      title: '登录页面',
      logStatus: false
    }
  }, {
    path: '/register',
    name: 'register',
    component: Register,
    meta: {
      title: '注册页面',
      logStatus: false
    }
  }, {
    path: '/main',
    name: 'main',
    component: Main,
    meta: {
      title: '后台管理页面',
      logStatus: true
    },
    children: [
      {
        path: '/home',
        name: '/home',
        component: Home,
        meta: {
          title: '后台管理页面',
          logStatus: true
        }
      }, {
        path: '/menu2/view1',
        name: '/menu2/view1',
        component: TestView1,
        meta: {
          title: '后台管理页面',
          logStatus: true
        }
      }, {
        path: '/menu2/view2',
        name: '/menu2/view2',
        component: TestView2,
        meta: {
          title: '后台管理页面',
          logStatus: false
        }
      }, {
        path: '/menu2/view3',
        name: '/menu2/view3',
        component: TestView3,
        meta: {
          title: '后台管理页面',
          logStatus: false
        }
      }, {
        path: '/menu3/view1',
        name: '/menu3/view1',
        component: TestView4,
        meta: {
          title: '后台管理页面',
          logStatus: false
        }
      }, {
        path: '/menu3/view2',
        name: '/menu3/view2',
        component: TestView2,
        meta: {
          title: '后台管理页面',
          logStatus: false
        }
      }, {
        path: '/menu4/view1',
        name: '/menu4/view1',
        component: TestView1,
        meta: {
          title: '后台管理页面',
          logStatus: false
        }
      }
    ]
  }]
})
